home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_qt.idb / usr / freeware / catman / p_man / cat3 / qcache.Z / qcache
Encoding:
Text File  |  1998-10-28  |  15.0 KB  |  265 lines

  1.  
  2.  
  3.  
  4.      QQQQCCCCaaaacccchhhheeee((((3333qqqqtttt))))    TTTTrrrroooollllllll TTTTeeeecccchhhh AAAASSSS ((((9999 JJJJuuuullllyyyy 1111999999998888))))       QQQQCCCCaaaacccchhhheeee((((3333qqqqtttt))))
  5.  
  6.  
  7.  
  8.      NNNNAAAAMMMMEEEE
  9.       QCache - Template class that provides    a cache    based on char*
  10.       keys
  11.  
  12.      SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  13.       #include <qcache.h>
  14.  
  15.       Inherits QGCache.
  16.  
  17.     PPPPuuuubbbblllliiiicccc MMMMeeeemmmmbbbbeeeerrrrssss
  18.       QQQQCCCCaaaacccchhhheeee (((( ccccoooonnnnsssstttt QQQQCCCCaaaacccchhhheeee<<<<ttttyyyyppppeeee>>>> &&&&    cccc ))))
  19.       QQQQCCCCaaaacccchhhheeee (((( iiiinnnntttt _m_a_x_C_o_s_t====111100000000,,,, iiiinnnntttt    _s_i_z_e====11117777,,,, bbbboooooooollll _c_s
  20.       ~~~~QQQQCCCCaaaacccchhhheeee ()
  21.       QQQQCCCCaaaacccchhhheeee<<<<ttttyyyyppppeeee>>>>&&&&    ooooppppeeeerrrraaaattttoooorrrr==== (((( ccccoooonnnnsssstttt QQQQCCCCaaaacccchhhheeee<<<<ttttyyyyppppeeee>>>> &&&& cccc ))))
  22.       iiiinnnntttt mmmmaaaaxxxxCCCCoooosssstttt (((()))) ccccoooonnnnsssstttt
  23.       iiiinnnntttt ttttoooottttaaaallllCCCCoooosssstttt    (((()))) ccccoooonnnnsssstttt
  24.       vvvvooooiiiidddd sssseeeettttMMMMaaaaxxxxCCCCoooosssstttt (((( iiiinnnntttt    mmmm ))))
  25.       vvvviiiirrrrttttuuuuaaaallll uuuuiiiinnnntttt ccccoooouuuunnnntttt (((())))    ccccoooonnnnsssstttt
  26.       uuuuiiiinnnntttt ssssiiiizzzzeeee (((()))) ccccoooonnnnsssstttt
  27.       bbbboooooooollll iiiissssEEEEmmmmppppttttyyyy (((()))) ccccoooonnnnsssstttt
  28.       bbbboooooooollll iiiinnnnsssseeeerrrrtttt ((((    ccccoooonnnnsssstttt cccchhhhaaaarrrr **** _k,,,,    ccccoooonnnnsssstttt ttttyyyyppppeeee **** _d,,,,    iiiinnnntttt _c
  29.       bbbboooooooollll rrrreeeemmmmoooovvvveeee ((((    ccccoooonnnnsssstttt cccchhhhaaaarrrr **** kkkk ))))
  30.       ttttyyyyppppeeee****    ttttaaaakkkkeeee (((( ccccoooonnnnsssstttt cccchhhhaaaarrrr **** kkkk ))))
  31.       vvvviiiirrrrttttuuuuaaaallll vvvvooooiiiidddd cccclllleeeeaaaarrrr (((())))
  32.       ttttyyyyppppeeee****    ffffiiiinnnndddd (((( ccccoooonnnnsssstttt cccchhhhaaaarrrr **** _k,,,, bbbboooooooollll _r_e_f====TTTTRRRRUUUUEEEE )))) ccccoooonnnnsssstttt
  33.       ttttyyyyppppeeee****    ooooppppeeeerrrraaaattttoooorrrr[[[[]]]] (((( ccccoooonnnnsssstttt cccchhhhaaaarrrr    **** kkkk )))) ccccoooonnnnsssstttt
  34.       vvvvooooiiiidddd ssssttttaaaattttiiiissssttttiiiiccccssss (((()))) ccccoooonnnnsssstttt
  35.  
  36.      DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  37.       The QCache class is a    template class that provides a cache
  38.       based    on char* keys.
  39.  
  40.       QCache is implemented    as both    a template and a macro class.
  41.       Define a template instance QCache<X> to create a cache that
  42.       operates on pointers to X, or    X*.
  43.  
  44.       A cache is a least recently used (LRU) list of cache items.
  45.       Each cache item has a    cost. The sum of item costs,
  46.       totalCost(), will not    exceed the maximum cache cost,
  47.       maxCost(). If    inserting a new    item would cause the total
  48.       cost to exceed the maximum cost, the least recently used
  49.       items    in the cache are deleted.
  50.  
  51.       Apart    from insert, by    far the    most important function    is
  52.       find() (which    also exists as operatior[]). This function
  53.       looks    up an item, returns it,    and by default marks it    as
  54.       being    the least recently used    item.
  55.  
  56.       There    are also methods to remove() an    object from the    cache
  57.       and delete it, and to    take() an object out of    the cache
  58.       without deleting it.
  59.  
  60.  
  61.  
  62.  
  63.      Page 1                         (printed 9/22/98)
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.      QQQQCCCCaaaacccchhhheeee((((3333qqqqtttt))))    TTTTrrrroooollllllll TTTTeeeecccchhhh AAAASSSS ((((9999 JJJJuuuullllyyyy 1111999999998888))))       QQQQCCCCaaaacccchhhheeee((((3333qqqqtttt))))
  71.  
  72.  
  73.  
  74.       The keys for the cache can be    case-sensitive or not, or
  75.       deeply copied    or not.    The constructor    lets you decide.
  76.  
  77.       QCache, as it    must, takes over ownership of the items    you
  78.       insert. That implies that it will delete the items at    its
  79.       discretion, and that you must    _n_o_t delete them. There is one
  80.       exception, however: If the cost of an    object you try to
  81.       insert() is higher than the allowed total cost of the    cache,
  82.       insert() returns FALSE and in    this case you must delete the
  83.       object yourself.
  84.  
  85.       In addition to totalCost() and maxCost()/setMaxCost(), there
  86.       are access functions to obtain the number of items in    the
  87.       cache    (count()), the size of the hash    array (size(), set
  88.       using    the constructor) and whether the cache is empty    (you
  89.       guessed it: isEmpty()). Finally, there is a statistics(),
  90.       which    prints various cache statistics    on stdout.
  91.  
  92.       There    is also    a QCacheIterator which may be used to traverse
  93.       the items in the cache in arbritrary order.
  94.  
  95.       See also: QCacheIterator, QIntCache and Collection Classes
  96.  
  97.      MMMMEEEEMMMMBBBBEEEERRRR FFFFUUUUNNNNCCCCTTTTIIIIOOOONNNN DDDDOOOOCCCCUUUUMMMMEEEENNNNTTTTAAAATTTTIIIIOOOONNNN
  98.      QQQQCCCCaaaacccchhhheeee::::::::QQQQCCCCaaaacccchhhheeee (((( ccccoooonnnnsssstttt QQQQCCCCaaaacccchhhheeee<<<<ttttyyyyppppeeee>>>> &&&& cccc ))))
  99.       For internal use only.
  100.  
  101.      QQQQCCCCaaaacccchhhheeee::::::::QQQQCCCCaaaacccchhhheeee (((( iiiinnnntttt mmmmaaaaxxxxCCCCoooosssstttt====111100000000,,,, iiiinnnntttt ssssiiiizzzzeeee====11117777,,,, bbbboooooooollll ccccssss====TTTTRRRRUUUUEEEE,,,, bbbboooooooollll
  102.       cccckkkk====TTTTRRRRUUUUEEEE ))))
  103.       Constructs an    empty cache with maximum allowed total cost
  104.       _m_a_x_C_o_s_t, optimized to    contain    a bit less than    _s_i_z_e items,
  105.       with case-sensitive keys if _c_s is TRUE (the default) and
  106.       case-insensitive keys    if _c_s is FALSE,    and whose keys are
  107.       deeply copied    on insertion (the default) and shallowly
  108.       copied of _c_k is FALSE.
  109.  
  110.      QQQQCCCCaaaacccchhhheeee::::::::~~~~QQQQCCCCaaaacccchhhheeee (((())))
  111.       Destroys the object and all objects in it.
  112.  
  113.      vvvvooooiiiidddd QQQQCCCCaaaacccchhhheeee::::::::cccclllleeeeaaaarrrr    (((()))) [[[[vvvviiiirrrrttttuuuuaaaallll]]]]
  114.       Removes all items from the cache, and    deletes    them.
  115.  
  116.       All cache iterators that operate this    on cache are reset.
  117.  
  118.       See also: remove() and take().
  119.  
  120.       Reimplemented    from QCollection.
  121.  
  122.      uuuuiiiinnnntttt QQQQCCCCaaaacccchhhheeee::::::::ccccoooouuuunnnntttt    (((()))) ccccoooonnnnsssstttt [[[[vvvviiiirrrrttttuuuuaaaallll]]]]
  123.       Returns the number of    items in the cache.
  124.  
  125.       See also: totalCost().
  126.  
  127.  
  128.  
  129.      Page 2                         (printed 9/22/98)
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.      QQQQCCCCaaaacccchhhheeee((((3333qqqqtttt))))    TTTTrrrroooollllllll TTTTeeeecccchhhh AAAASSSS ((((9999 JJJJuuuullllyyyy 1111999999998888))))       QQQQCCCCaaaacccchhhheeee((((3333qqqqtttt))))
  137.  
  138.  
  139.  
  140.       Reimplemented    from QCollection.
  141.  
  142.      ttttyyyyppppeeee **** QQQQCCCCaaaacccchhhheeee::::::::ffffiiiinnnndddd (((( ccccoooonnnnsssstttt cccchhhhaaaarrrr ****    kkkk,,,, bbbboooooooollll    rrrreeeeffff====TTTTRRRRUUUUEEEE )))) ccccoooonnnnsssstttt
  143.       Returns the item associated with \ k,    or null    if the key
  144.       does not exist in the    cache. If _r_e_f is TRUE (the default),
  145.       the item is moved to the front of the    LRU list.
  146.  
  147.       If there are two or more items with equal keys, then the one
  148.       that was inserted last is returned.
  149.  
  150.      bbbboooooooollll QQQQCCCCaaaacccchhhheeee::::::::iiiinnnnsssseeeerrrrtttt (((( ccccoooonnnnsssstttt cccchhhhaaaarrrr ****    kkkk,,,, ccccoooonnnnsssstttt ttttyyyyppppeeee ****    dddd,,,, iiiinnnntttt cccc====1111,,,,
  151.       iiiinnnntttt pppp====0000 ))))
  152.       Inserts the item _d into the cache with key _k,    cost and
  153.       priority _p, and returns TRUE if it is    successful and FALSE
  154.       if it    fails.
  155.  
  156.       The cache's size is limited, and if the total    cost is    too
  157.       high,    QCache will delete some    of the least-used objects.
  158.  
  159.       WWWWaaaarrrrnnnniiiinnnngggg:::: If this function returns FALSE, you must delete _d
  160.       yourself. Additionally, be very careful about    using _d    after
  161.       calling this function, as any    other insertions into the
  162.       cache, from anywhere in the application, or within Qt
  163.       itself, could    cause the object to be discarded from the
  164.       cache, and the pointer to become invalid.
  165.  
  166.      bbbboooooooollll QQQQCCCCaaaacccchhhheeee::::::::iiiissssEEEEmmmmppppttttyyyy (((()))) ccccoooonnnnsssstttt
  167.       Returns TRUE if the cache is empty, or TRUE if there is at
  168.       least    one object in it.
  169.  
  170.      iiiinnnntttt QQQQCCCCaaaacccchhhheeee::::::::mmmmaaaaxxxxCCCCoooosssstttt (((()))) ccccoooonnnnsssstttt
  171.       Returns the maximum allowed total cost of the    cache.
  172.  
  173.       See also: setMaxCost() and totalCost().
  174.  
  175.      QQQQCCCCaaaacccchhhheeee<<<<ttttyyyyppppeeee>>>>&&&& QQQQCCCCaaaacccchhhheeee::::::::ooooppppeeeerrrraaaattttoooorrrr==== (((( ccccoooonnnnsssstttt QQQQCCCCaaaacccchhhheeee<<<<ttttyyyyppppeeee>>>> &&&& cccc ))))
  176.       For internal use only.
  177.  
  178.      ttttyyyyppppeeee **** QQQQCCCCaaaacccchhhheeee::::::::ooooppppeeeerrrraaaattttoooorrrr[[[[]]]] (((( ccccoooonnnnsssstttt cccchhhhaaaarrrr **** kkkk    )))) ccccoooonnnnsssstttt
  179.       Returns the item associated with _k, or null if _k does    not
  180.       exist    in the cache, and moves    the item to the    front of the
  181.       LRU list.
  182.  
  183.       If there are two or more items with equal keys, then the one
  184.       that was inserted last is returned.
  185.  
  186.       This is the same as find( k, TRUE ).
  187.  
  188.       See also: find().
  189.  
  190.      bbbboooooooollll QQQQCCCCaaaacccchhhheeee::::::::rrrreeeemmmmoooovvvveeee (((( ccccoooonnnnsssstttt cccchhhhaaaarrrr ****    kkkk ))))
  191.       Deletes the item associated with _k, and returns TRUE if the
  192.  
  193.  
  194.  
  195.      Page 3                         (printed 9/22/98)
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.      QQQQCCCCaaaacccchhhheeee((((3333qqqqtttt))))    TTTTrrrroooollllllll TTTTeeeecccchhhh AAAASSSS ((((9999 JJJJuuuullllyyyy 1111999999998888))))       QQQQCCCCaaaacccchhhheeee((((3333qqqqtttt))))
  203.  
  204.  
  205.  
  206.       item was present in the cache    or FALSE if it was not.
  207.  
  208.       If there are two or more items with equal keys, then the one
  209.       that was inserted last is is deleted.
  210.  
  211.       All iterators    that refer to the removed item are set to
  212.       point    to the next item in the    cache's    traversal order.
  213.  
  214.       See also: take() and clear().
  215.  
  216.      vvvvooooiiiidddd QQQQCCCCaaaacccchhhheeee::::::::sssseeeettttMMMMaaaaxxxxCCCCoooosssstttt (((( iiiinnnntttt mmmm ))))
  217.       Sets the maximum allowed total cost of the cache to _m. If
  218.       the current total cost is above _m, some items    are deleted
  219.       immediately.
  220.  
  221.       See also: maxCost() and totalCost().
  222.  
  223.      uuuuiiiinnnntttt QQQQCCCCaaaacccchhhheeee::::::::ssssiiiizzzzeeee (((()))) ccccoooonnnnsssstttt
  224.       Returns the size of the hash array used to implement the
  225.       cache. This should be    a bit bigger than count() is likely to
  226.       be.
  227.  
  228.      ttttyyyyppppeeee **** QQQQCCCCaaaacccchhhheeee::::::::ttttaaaakkkkeeee (((( ccccoooonnnnsssstttt cccchhhhaaaarrrr ****    kkkk ))))
  229.       Takes    the item associated with _k out of the cache without
  230.       deleting it, and returns a pointer to    the item taken out, or
  231.       null if the key does not exist in the    cache.
  232.  
  233.       If there are two or more items with equal keys, then the one
  234.       that was inserted last is taken.
  235.  
  236.       All iterators    that refer to the taken    item are set to    point
  237.       to the next item in the cache's traversal order.
  238.  
  239.       See also: remove() and clear().
  240.  
  241.      iiiinnnntttt QQQQCCCCaaaacccchhhheeee::::::::ttttoooottttaaaallllCCCCoooosssstttt (((()))) ccccoooonnnnsssstttt
  242.       Returns the total cost of the    items in the cache. This is an
  243.       integer in the range 0 to maxCost().
  244.  
  245.       See also:  setMaxCost().
  246.  
  247.      SSSSEEEEEEEE AAAALLLLSSSSOOOO
  248.       hhhhttttttttpppp::::////////wwwwwwwwwwww....ttttrrrroooollllllll....nnnnoooo////qqqqtttt////qqqqccccaaaacccchhhheeee....hhhhttttmmmmllll
  249.  
  250.      CCCCOOOOPPPPYYYYRRRRIIIIGGGGHHHHTTTT
  251.       Copyright 1992-1997 Troll Tech AS.  See the LICENSE file
  252.       included in the distribution for a complete license
  253.       statement.
  254.  
  255.      AAAAUUUUTTTTHHHHOOOORRRR
  256.       Generated automatically from the source code.
  257.  
  258.  
  259.  
  260.  
  261.      Page 4                         (printed 9/22/98)
  262.  
  263.  
  264.  
  265.